/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Presentacion;


import Negocio.Empresa;
import Negocio.Agricola;
import Negocio.Mantenimiento;
import Negocio.Rodado;
import Negocio.Vehiculo;
import java.util.Iterator;
import java.util.Map;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;

/**
 *
 * @author robert
 */
public class DlgVehiculo extends javax.swing.JDialog {

    private Empresa miEmpresa;
    private Vehiculo unVehiculo;
    private Agricola unVehiculoAgricola;
    private Rodado unVehiculoRodado;
    DefaultListModel modelVehiculos = new DefaultListModel();
    DefaultListModel modelMantenimientos = new DefaultListModel();

    /**
     * Creates new form FrmVehiculo
     */
    public DlgVehiculo(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        //miEmpresa = new TPFinal().obtenerEmpresa();
        initComponents();
    }

    public DlgVehiculo(java.awt.Frame parent, boolean modal, Empresa miEmpresa) {
        initComponents();
        this.miEmpresa = miEmpresa;
        this.inicializar();
        
    }
    
    //mis Metodos
    public void inicializar(){
        this.ListVehiculos.setModel(modelVehiculos);
        this.ListMantenimientos.setModel(modelMantenimientos);
        this.cargarVehiculos();
         this.unVehiculo=null;
        this.unVehiculoAgricola=null;
        this.unVehiculoRodado =null;
        
        this.TxtEstado.setText("");
        this.TxtHorasUso.setText("");
        this.TxtInterno.setText("");
        this.TxtKilometraje.setText("");
        this.TxtMatricula.setText("");
        this.TxtModelo.setText("");
        this.TxtTara.setText("");
        
        this.TxtEstado.setEnabled(false);
        this.TxtHorasUso.setEnabled(false);
        this.TxtInterno.setEnabled(false);
        this.TxtKilometraje.setEnabled(false);
        this.TxtMatricula.setEnabled(false);
        this.TxtModelo.setEnabled(false);
        this.TxtTara.setEnabled(false);
        
        this.BtnCancel.setEnabled(false);
        this.BtnEliminar.setEnabled(false);
        this.BtnGuardar.setEnabled(false);
        this.BtnNuevo.setEnabled(true);
        
        this.RadioBtnAgricola.setSelected(false);
        this.RadioBtnAgricola.setEnabled(false);
        this.RadioBtnRodado.setSelected(false);
        this.RadioBtnRodado.setEnabled(false);
    }
    
    public void cargarVehiculos(){
        this.modelVehiculos.clear();
        
        if( this.miEmpresa.getVehiculosActivos().size() > 0){
            for (Map.Entry vehiculo : this.miEmpresa.getVehiculosActivos().entrySet()) {
                this.modelVehiculos.addElement((Vehiculo) vehiculo.getValue());
            }
        }else{
            this.modelVehiculos.addElement("No se Encontraron Vehiculos");
        } 
    }
    
    public void completarCampos(){
        this.TxtMatricula.setText(this.unVehiculo.getMatricula());
        this.TxtInterno.setText(this.unVehiculo.getNro().toString());
        this.TxtModelo.setText(this.unVehiculo.getModelo().toString());
        
        if(this.unVehiculo.isAgricola()){
            this.completarAgricola();
        }else{
            this.completarRodado();
        }
        
        this.BtnGuardar.setEnabled(true);
        this.BtnNuevo.setEnabled(false);
        this.cargarMantenimientos();
        
        this.TxtEstado.setEnabled(true);
        this.TxtInterno.setEnabled(true);
        this.TxtMatricula.setEnabled(true);
        this.TxtModelo.setEnabled(true);

        this.BtnCancel.setEnabled(true);
        this.BtnEliminar.setEnabled(true);
        this.BtnGuardar.setEnabled(true);
        this.BtnNuevo.setEnabled(false);
        
        
        this.RadioBtnAgricola.setEnabled(false);       
        this.RadioBtnRodado.setEnabled(false);
    }
    
    public void cargarMantenimientos(){
        this.modelMantenimientos.clear();
        if(this.unVehiculo.getMantenimientos() != null && this.unVehiculo.getMantenimientos().size() > 0){
        Iterator it = this.unVehiculo.getMantenimientos().iterator();
        while(it.hasNext()){
             this.modelMantenimientos.addElement((Mantenimiento) it.next());
        }
        }else{
            this.modelMantenimientos.addElement("No se Encontraron Mantenimientos");
        }
                
        
    }
    public void completarAgricola(){
        this.habilitarAgricolas(); 
        this.TxtHorasUso.setText(this.unVehiculoAgricola.getHorasUso().toString());
        this.TxtTara.setText(this.unVehiculoAgricola.getTara().toString());
        this.RadioBtnAgricola.setSelected(true);
        this.RadioBtnAgricola.setEnabled(false);
        this.RadioBtnRodado.setEnabled(false);
        this.unVehiculoAgricola = (Agricola) this.unVehiculo;
        this.TxtTara.setEnabled(true);
        this.TxtHorasUso.setEnabled(true);
                
        
    }
    public void completarRodado(){
        this.habilitarRodados();
        this.TxtKilometraje.setText(this.unVehiculoRodado.getKilometraje().toString());
        this.RadioBtnRodado.setSelected(true);
        this.RadioBtnRodado.setEnabled(false);
        this.RadioBtnAgricola.setEnabled(false);
        this.unVehiculoRodado = (Rodado) this.unVehiculo;
        this.TxtKilometraje.setEnabled(true);
        
    }
    
     public void habilitarAgricolas(){
         this.unVehiculoAgricola = (Agricola) this.unVehiculo;
         this.TxtHorasUso.setEnabled(true);
         this.TxtTara.setEnabled(true);
         this.TxtKilometraje.setEnabled(false);
     }
     public void habilitarRodados(){
         this.unVehiculoRodado = (Rodado) this.unVehiculo;
         this.TxtHorasUso.setEnabled(false);
         this.TxtTara.setEnabled(false);
         this.TxtKilometraje.setEnabled(true);
         
     }
     

    //Fin Mis Metodos

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        BtnGroupTipo = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        ListVehiculos = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        ListMantenimientos = new javax.swing.JList();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel6 = new javax.swing.JLabel();
        RadioBtnRodado = new javax.swing.JRadioButton();
        RadioBtnAgricola = new javax.swing.JRadioButton();
        LblAtributoTipo = new javax.swing.JLabel();
        TxtKilometraje = new javax.swing.JFormattedTextField();
        TxtModelo = new javax.swing.JFormattedTextField();
        TxtMatricula = new javax.swing.JFormattedTextField();
        TxtInterno = new javax.swing.JFormattedTextField();
        BtnNuevo = new javax.swing.JButton();
        BtnGuardar = new javax.swing.JButton();
        BtnEliminar = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        TxtHorasUso = new javax.swing.JFormattedTextField();
        TxtTara = new javax.swing.JFormattedTextField();
        jLabel9 = new javax.swing.JLabel();
        TxtEstado = new javax.swing.JTextField();
        BtnCancel = new javax.swing.JButton();
        BtnAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Vehículos");
        setMinimumSize(new java.awt.Dimension(700, 550));
        setModal(true);
        setPreferredSize(new java.awt.Dimension(700, 550));

        ListVehiculos.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        ListVehiculos.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        ListVehiculos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ListVehiculosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(ListVehiculos);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel1.setLabelFor(TxtMatricula);
        jLabel1.setText("Matrícula");

        jLabel2.setText("Modelo");

        jLabel3.setText("Interno");

        ListMantenimientos.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane2.setViewportView(ListMantenimientos);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel4.setText("Vehículos");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel5.setText("Mantenimientos");

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jLabel6.setText("Tipo");

        BtnGroupTipo.add(RadioBtnRodado);
        RadioBtnRodado.setText("Rodado");
        RadioBtnRodado.setEnabled(false);
        RadioBtnRodado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RadioBtnRodadoActionPerformed(evt);
            }
        });

        BtnGroupTipo.add(RadioBtnAgricola);
        RadioBtnAgricola.setText("Agrícola");
        RadioBtnAgricola.setEnabled(false);
        RadioBtnAgricola.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RadioBtnAgricolaActionPerformed(evt);
            }
        });

        LblAtributoTipo.setText("Kilometraje");

        TxtKilometraje.setEnabled(false);

        TxtModelo.setEnabled(false);
        TxtModelo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TxtModeloActionPerformed(evt);
            }
        });

        TxtMatricula.setEnabled(false);

        TxtInterno.setEnabled(false);

        BtnNuevo.setText("Nuevo");
        BtnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnNuevoActionPerformed(evt);
            }
        });

        BtnGuardar.setText("Guardar");
        BtnGuardar.setEnabled(false);
        BtnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnGuardarActionPerformed(evt);
            }
        });

        BtnEliminar.setText("Eliminar");
        BtnEliminar.setEnabled(false);
        BtnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnEliminarActionPerformed(evt);
            }
        });

        jLabel7.setText("Horas de uso");

        jLabel8.setText("Tara");

        TxtHorasUso.setEnabled(false);

        TxtTara.setEnabled(false);

        jLabel9.setText("Estado");

        TxtEstado.setEnabled(false);

        BtnCancel.setText("Cancelar");
        BtnCancel.setEnabled(false);
        BtnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnCancelActionPerformed(evt);
            }
        });

        BtnAceptar.setText("Aceptar");
        BtnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator2)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(BtnNuevo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(BtnGuardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(BtnEliminar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(BtnCancel))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(LblAtributoTipo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel8))
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(RadioBtnRodado)
                                .addGap(18, 18, 18)
                                .addComponent(RadioBtnAgricola))
                            .addComponent(TxtKilometraje)
                            .addComponent(TxtHorasUso)
                            .addComponent(TxtTara)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(TxtInterno, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
                            .addComponent(TxtModelo)
                            .addComponent(TxtMatricula)
                            .addComponent(TxtEstado)))
                    .addComponent(BtnAceptar, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jSeparator1)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(TxtMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(TxtModelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel2))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(TxtInterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel9)
                                    .addComponent(TxtEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(RadioBtnRodado)
                                    .addComponent(RadioBtnAgricola)
                                    .addComponent(jLabel6))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(TxtKilometraje, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(LblAtributoTipo))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel7)
                                    .addComponent(TxtHorasUso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(TxtTara, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel8))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(BtnNuevo)
                                    .addComponent(BtnGuardar)
                                    .addComponent(BtnEliminar)
                                    .addComponent(BtnCancel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(8, 8, 8)
                                .addComponent(BtnAceptar))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 510, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void TxtModeloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TxtModeloActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TxtModeloActionPerformed

    private void BtnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnGuardarActionPerformed
        // TODO add your handling code here:
        try {
            if (this.unVehiculo == null) {
                if(this.RadioBtnRodado.isSelected()){                    
                    this.miEmpresa.nuevoVehiculoRodado(this.TxtMatricula.getText(), Integer.parseInt(this.TxtModelo.getText()), Integer.parseInt(this.TxtInterno.getText()), Integer.parseInt(this.TxtKilometraje.getText()),this.TxtEstado.getText());
                }else{
                    miEmpresa.nuevoVehiculoAgricola(this.TxtMatricula.getText(),Integer.parseInt(this.TxtModelo.getText()),Integer.parseInt(this.TxtInterno.getText()),Integer.parseInt(this.TxtHorasUso.getText()),Integer.parseInt(this.TxtTara.getText()),this.TxtEstado.getText());
                }
                JOptionPane.showMessageDialog(this, "Se ha creado con exito.");
            } else {
                if(this.unVehiculo.isAgricola()){
                    
                    this.miEmpresa.modificarAgricola(this.unVehiculoAgricola,this.TxtMatricula.getText(),Integer.parseInt(this.TxtModelo.getText()),Integer.parseInt(this.TxtInterno.getText()),Integer.parseInt(this.TxtHorasUso.getText()),Integer.parseInt(this.TxtTara.getText()),this.TxtEstado.getText());
                }else{
                    this.miEmpresa.modificarRodado(this.unVehiculoRodado,this.TxtMatricula.getText(), Integer.parseInt(this.TxtModelo.getText()), Integer.parseInt(this.TxtInterno.getText()), Integer.parseInt(this.TxtKilometraje.getText()),this.TxtEstado.getText());
                }
                JOptionPane.showMessageDialog(this, "Se ha modificado con exito.");
            }
            this.inicializar();
            
            
        } catch (Exception e) {
           // e.printStackTrace();
            JOptionPane.showMessageDialog(this, "ALGO PASO: "+e.getMessage());
        }
    }//GEN-LAST:event_BtnGuardarActionPerformed

    private void ListVehiculosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ListVehiculosMouseClicked
        // TODO add your handling code here:
        //this.inicializar();
        if(this.modelVehiculos.size() > 0){
            this.unVehiculo = (Vehiculo) this.modelVehiculos.getElementAt(this.ListVehiculos.getSelectedIndex());
            this.completarCampos();
            this.BtnCancel.setEnabled(true);
            this.BtnEliminar.setEnabled(true);
            this.BtnNuevo.setEnabled(false);
        }
    }//GEN-LAST:event_ListVehiculosMouseClicked

    private void BtnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnNuevoActionPerformed
        // TODO add your handling code here:
        this.BtnGuardar.setEnabled(true);
        this.BtnNuevo.setEnabled(false);
        this.BtnCancel.setEnabled(true);
        this.BtnEliminar.setEnabled(true);
        this.TxtEstado.setEnabled(true);
        this.TxtHorasUso.setEnabled(true);
        this.TxtInterno.setEnabled(true);
        this.TxtKilometraje.setEnabled(true);
        this.TxtMatricula.setEnabled(true);
        this.TxtModelo.setEnabled(true);
        this.TxtTara.setEnabled(true);
        this.RadioBtnAgricola.setEnabled(true);
        this.RadioBtnRodado.setEnabled(true);
        
        
    }//GEN-LAST:event_BtnNuevoActionPerformed

    private void RadioBtnRodadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RadioBtnRodadoActionPerformed
        // TODO add your handling code here:
        this.habilitarRodados();
       
    }//GEN-LAST:event_RadioBtnRodadoActionPerformed

    private void RadioBtnAgricolaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RadioBtnAgricolaActionPerformed
        // TODO add your handling code here:
        this.habilitarAgricolas();
    }//GEN-LAST:event_RadioBtnAgricolaActionPerformed

    private void BtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnAceptarActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_BtnAceptarActionPerformed

    private void BtnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnEliminarActionPerformed
        // TODO add your handling code here:
       // this.miEmpresa.quitarVehiculo(this.u)
        int mc,bc,ch=1;
        mc = JOptionPane.QUESTION_MESSAGE;
        bc = JOptionPane.YES_NO_CANCEL_OPTION;
        ch = JOptionPane.showConfirmDialog (this, "Desea quitar este Vehiculor?", "Confirmacion", bc, mc); 
        if(ch == 0){ 
            this.miEmpresa.quitarVehiculo(this.unVehiculo);
            JOptionPane.showMessageDialog(this, "La operacion se ha realizado exito.");
            this.inicializar();
            
        }
    }//GEN-LAST:event_BtnEliminarActionPerformed

    private void BtnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnCancelActionPerformed
        // TODO add your handling code here:
       this.inicializar();
               
    }//GEN-LAST:event_BtnCancelActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void mains(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DlgVehiculo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DlgVehiculo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DlgVehiculo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DlgVehiculo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog 
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                DlgVehiculo dialog = new DlgVehiculo(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                //dialog.setVisible(true);
            }
        });*/
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnAceptar;
    private javax.swing.JButton BtnCancel;
    private javax.swing.JButton BtnEliminar;
    private javax.swing.ButtonGroup BtnGroupTipo;
    private javax.swing.JButton BtnGuardar;
    private javax.swing.JButton BtnNuevo;
    private javax.swing.JLabel LblAtributoTipo;
    private javax.swing.JList ListMantenimientos;
    private javax.swing.JList ListVehiculos;
    private javax.swing.JRadioButton RadioBtnAgricola;
    private javax.swing.JRadioButton RadioBtnRodado;
    private javax.swing.JTextField TxtEstado;
    private javax.swing.JFormattedTextField TxtHorasUso;
    private javax.swing.JFormattedTextField TxtInterno;
    private javax.swing.JFormattedTextField TxtKilometraje;
    private javax.swing.JFormattedTextField TxtMatricula;
    private javax.swing.JFormattedTextField TxtModelo;
    private javax.swing.JFormattedTextField TxtTara;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    // End of variables declaration//GEN-END:variables
}
